package M;

public class Myduilie {

    class Node{
        public  int val;
        public  Node next;
        public  Node(int val){
            this.val=val;
        }
    }
    public  Node head;
    public  Node last;
    public  int usedSize;

    public  void offer(int val){
        Node node =new Node(val);
        if(head==null){
            head =node;
            last=node;
        }
        else {
            last.next=node;
            last=node;
        }
        usedSize++;
    }
    public  int poll(){
        if(empty()){
            throw  new RuntimeException("error");
        }
        int val =head.val;
        head=head.next;
        if(head==null){
            last=null;
        }
        usedSize--;
        return  val;
    }
    public  int peek(){
        if(empty()){
            throw  new RuntimeException("error");
        }
        return head.val;
    }
    public  int size(){
        return  usedSize;
    }
    public  boolean empty(){
        return usedSize==0;
    }


}

